package org.surfnet.oaaas.it;

import org.junit.Test;
import static org.junit.Assert.assertEquals; 
import com.sun.jersey.api.client.ClientResponse;
import org.surfnet.oaaas.model.VerifyTokenResponse;

public class VerifyResourceTestIT extends AbstractAuthorizationServerTest {
//	@Test
//	public void withNoParams() {
//		final ClientResponse response = client.resource(baseUrlWith("/v1/tokeninfo")).get(ClientResponse.class);
//		assertEquals(401, response.getStatus());
//	}
//
//	@Test
//	public void withNoAuthorizationHeader() {
//		final ClientResponse response = client.resource(baseUrlWith("/v1/tokeninfo"))
//				.queryParam("access_token", "boobaa").get(ClientResponse.class);
//		assertEquals(401, response.getStatus());
//	}
//
//	@Test
//	public void withInvalidAuthorizationHeader() {
//		final ClientResponse response = client.resource(baseUrlWith("/v1/tokeninfo")).queryParam("access_token", "boobaa")
//				.header("Authorization", "NotBasicButGarbage abb ccc dd").get(ClientResponse.class);
//		assertEquals(401, response.getStatus());
//	}
//
//	@Test
//	public void withValidAuthorizationHeaderButNoAccessToken() {
//		final ClientResponse response = client.resource(baseUrlWith("/v1/tokeninfo"))
//				.header("Authorization", authorizationBasic("user", "pass")).get(ClientResponse.class);
//		assertEquals(401, response.getStatus());
//	}

	@Test
	public void happy() {  
		final ClientResponse response = client.resource(baseUrlWith("/v1/tokeninfo"))
				.queryParam("access_token", "00-11-22-33").header("Authorization",
						authorizationBasic("it-test-resource-server","somesecret")).accept("application/json").get(ClientResponse.class);
		assertEquals(200, response.getStatus());  
		String responseString = response.getEntity(String.class);
		System.out.println("responseString:" + responseString);
		
		//Error because VerifyResource's verifyToken not return entity, otherwise it return string
		//final VerifyTokenResponse verifyTokenResponse = response.getEntity(VerifyTokenResponse.class);
		//assertEquals("it-test-enduser", verifyTokenResponse.getPrincipal().getName());
	}
}
